/*
 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 *
 * This file is part of the lwIP TCP/IP stack.
 *
 * Author: Adam Dunkels <adam@sics.se>
 *
 */
#ifndef __OS_ARCH_H__
#define __OS_ARCH_H__


#ifdef __cplusplus
extern "C" {
#endif

/* include */
#include "arch/cc.h"
#include  <ucos_ii.h>

/**
 * Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores
 * should be used instead
 */
#ifndef LWIP_COMPAT_MUTEX
#define LWIP_COMPAT_MUTEX     1
#endif

#define sys_arch_protect(void)            OS_CPU_SR_Save()
#define sys_arch_unprotect(lev_protect)   OS_CPU_SR_Restore(lev_protect)

/**
 * lwip mailbox
 */
#ifndef LWIP_MBOX_SIZE
#define LWIP_MBOX_SIZE        16
#endif

#ifndef LWIP_MBOX_MSG_SIZE
#define LWIP_MBOX_MSG_SIZE    32
#endif

typedef struct lwip_mbox_s {
    OS_EVENT* mbox;
    void*     msg[LWIP_MBOX_MSG_SIZE];
    struct lwip_mbox_s *next;
} lwip_mbox_t;

/**
 * Arch dependent types for the following objects:
 *  sys_sem_t, sys_mbox_t, sys_thread_t,
 * And, optionally:
 *  sys_prot_t
 */
typedef OS_EVENT*         sys_sem_t;        /*  lwip semaphore  */
typedef lwip_mbox_t*      sys_mbox_t;       /*  lwip mailbox    */
typedef u8_t              sys_thread_t;     /*  lwip task ID    */
typedef u32_t             sys_prot_t;       /*  lwip prot for cpu register  */

/**
 * Defines to set vars of sys_mbox_t and sys_sem_t to NULL.
 *  SYS_MBOX_NULL NULL
 *  SYS_SEM_NULL  NULL
 */
#define SYS_MBOX_NULL    (void *)0
#define SYS_SEM_NULL     (void *)0

void sys_time_delay(u32_t time_ms);

#ifdef __cplusplus
}
#endif


#endif /* __OS_ARCH_H__ */

